/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import Globals.AllGlobal;
import brain.MyBrain;
import component.stylesheet.XlsLoader;
import component.stylesheet.XlsSave;
import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;
import myfx.jfxpanel.MyMenu;
import myfx.jfxpanel.MyTreeContainer;
import myjme.JmeCanvas;
import component.xml.XMLLoader;
import component.xml.XMLSave;
import database.operate.OperateMyDatabaseImpl;
import helptest.DiCengOper;
import java.awt.Canvas;
import java.util.ArrayList;
import model.GongZuoMian_Model;
import myfx.jfxpanel.JStatusBarImpl;
import myprogramui.comp.page2comp.FXTreeForJME;

/**
 *
 * @author Administrator
 */
public class MyController {
    private FXTreeForJME fXTreeForJME;
    private DiCengOper dco;
    private int viewShow=AllGlobal.VIEW_THREE_D;
    private MyTreeContainer fxContainer;
    private MyMenu fxMenu;
    private JStatusBarImpl myStatus;
    private JmeCanvas jmeCanvas;
    private MyBrain brain;
    private Canvas canvas;
    private float FANGWEIJIAO=95.59f;
    private float FACTOR=2.0f;
    private String zhuangtai="此为程序当前状态";
    private String guangbiaoxz="此为光标当前位置";
    private String bianjizt="此为当前编辑状态";
    private String beizhu="钻孔备注";
    private String dbfilepath="labdb.xml";
    private String loadfilepath="";
    private String dxfpath="D:/";
    private String excelpath="";
    private String excelloadpath="";
    private String docpath="";
    
    //下面这个是比较特别的，煤层倾角
    private float MEICENGQINGJIAOF=0;
    
    private int zuankongType= AllGlobal.CYLINDER_TYPE;
    private int GZM_TYPE=AllGlobal.GZM_TYPE_LEFT;
    private float gzmzxcd=800.0f;  
    private float zhongyajixian=13.0f;
    private int zuankongjiancejingdu=5;
    private float ahcjl=60;
    
    private XMLSave saveXML;
    private XMLLoader loadXML;
    
    private XlsLoader loadXsl;
    private XlsSave saveXsl;
    public MyController(FXTreeForJME fXTreeForJME,MyTreeContainer fxContainer,MyMenu fxMenu, JStatusBarImpl myStatus,JmeCanvas jmeCanvas,Canvas canvas){
        this.fXTreeForJME=fXTreeForJME;
        this.canvas=canvas;
        File file=new File("haha.txt");
        String str=file.getAbsolutePath();
        String strnew=str.replaceAll(file.getName(), "");
        docpath=strnew+"javadoc\\index.html";
        saveXML=new XMLSave(dbfilepath);
        loadXML=new XMLLoader(loadfilepath,fxContainer,this);
        saveXsl=new XlsSave(excelpath);
        loadXsl=new XlsLoader(excelloadpath,fxContainer,this);
        this.fxContainer=fxContainer;
        this.fxMenu=fxMenu;
        this.myStatus=myStatus;
        this.jmeCanvas=jmeCanvas;
        addControllerAll();
    }
    //添加控制器
    private synchronized void addControllerAll(){
        fxContainer.addController(this);
        fXTreeForJME.addController(this);
        fxMenu.addController(this);
        myStatus.addController(this);
        jmeCanvas.addController(this);
        
    }
    public FXTreeForJME getTreeForJME(){
        return this.fXTreeForJME;
    }
    public synchronized MyTreeContainer getFxContainer() {
        return fxContainer;
    }

    public synchronized MyMenu getFxMenu() {
        return fxMenu;
    }

    public synchronized JStatusBarImpl getFxStatus() {
        return myStatus;
    }

    public synchronized JmeCanvas getJmeCanvas() {
        return jmeCanvas;
    }
    public synchronized void addBrain(MyBrain brain){
        this.brain=brain;
    }

    public synchronized float getFANGWEIJIAO() {
        try {
            ArrayList<GongZuoMian_Model> gzmms= OperateMyDatabaseImpl.getAllResult(AllGlobal.GONGZUOMIAN_SQL);
            if(gzmms.size()>0){
                GongZuoMian_Model gzmm=gzmms.get(0);
                this.FANGWEIJIAO=Float.parseFloat(gzmm.getGzmfwj());
            }
           
        } catch (Exception ex) {
            Logger.getLogger(MyController.class.getName()).log(Level.SEVERE, null, ex);
        }
        return FANGWEIJIAO;
    }

    public synchronized void setFANGWEIJIAO(float FANGWEIJIAO) {
        this.FANGWEIJIAO = FANGWEIJIAO;
    }

    public synchronized float getFACTOR() {
        return FACTOR;
    }

    public synchronized void setFACTOR(float FACTOR) {
        this.FACTOR = FACTOR;
    }

    public synchronized String getZhuangtai() {
        return zhuangtai;
    }

    public synchronized void setZhuangtai(String zhuangtai) {
        this.zhuangtai = zhuangtai;
    }

    public synchronized String getGuangbiaoxz() {
        return guangbiaoxz;
    }

    public synchronized void setGuangbiaoxz(String guangbiaoxz) {
        this.guangbiaoxz = guangbiaoxz;
    }

    public synchronized String getBianjizt() {
        return bianjizt;
    }

    public synchronized void setBianjizt(String bianjizt) {
        this.bianjizt = bianjizt;
    }

    public synchronized String getBeizhu() {
        return beizhu;
    }

    public synchronized void setBeizhu(String beizhu) {
        this.beizhu = beizhu;
    }

    public int getZuankongType() {
        return zuankongType;
    }

    public void setZuankongType(int zuankongType) {
        this.zuankongType = zuankongType;
    }
  
    public String getDbfilepath() {
        return dbfilepath;
    }

    public void setDbfilepath(String dbfilepath) {
        this.dbfilepath = dbfilepath;
    }

    public String getDxfpath() {
        return dxfpath;
    }

    public void setDxfpath(String dxfpath) {
        this.dxfpath = dxfpath;
    }

    public String getDocpath() {
        return docpath;
    }

    public void setDocpath(String docpath) {
        this.docpath = docpath;
    }
    public void doLoadFile(String filepathString) throws Exception{
        this.loadfilepath=filepathString;
        this.loadXML.setFilepath(filepathString);
        loadXML.doLoad();
    }
    public void makeNewFile(String filepathString){
        this.dbfilepath=filepathString;
        saveXML.setFilepath(dbfilepath);
    }
    public void saveFile(String filepathString) throws Exception{
        this.dbfilepath=filepathString;
        saveXML.setFilepath(dbfilepath);
        saveXML.addAll();
        saveXML.saveData();
        myStatus.updateStatus("XML文件导出完成", this.toString(), "保存状态", "文件位置："+filepathString);
    }
    public void doLoadExcelFile(String filepath){
        try {
            this.excelloadpath=filepath;
            loadXsl.setFilepath(this.excelloadpath);
            loadXsl.doLoad();
        } catch (Exception ex) {
            Logger.getLogger(MyController.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    public void saveExcelFile(String filepath){
        this.excelpath=filepath;        
        try {
            saveXsl.setController(this);
            saveXsl.setFilepath(filepath);
            saveXsl.addAll();
            saveXsl.saveData();
            myStatus.updateStatus("Excel表格导出完成", this.toString(), "保存状态", "文件位置："+filepath);
        } catch (Exception ex) {
            Logger.getLogger(MyController.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }
    public String getExcelpath() {
        return excelpath;
    }

    public void setExcelpath(String excelpath) {
        this.excelpath = excelpath;
    }

    public int getGZM_TYPE() {
        return GZM_TYPE;
    }

    public void setGZM_TYPE(int GZM_TYPE) {
        this.GZM_TYPE = GZM_TYPE;
    }

    public float getGzmzxcd() {
        return gzmzxcd;
    }

    public void setGzmzxcd(float gzmzxcd) {
        this.gzmzxcd = gzmzxcd;
    }

    public float getZhongyajixian() {
        return zhongyajixian;
    }

    public void setZhongyajixian(float zhongyajixian) {
        this.zhongyajixian = zhongyajixian;
    }

    public int getZuankongjiancejingdu() {
        return zuankongjiancejingdu;
    }

    public void setZuankongjiancejingdu(int zuankongjiancejingdu) {
        this.zuankongjiancejingdu = zuankongjiancejingdu;
    }

    public Canvas getCanvas() {
        return canvas;
    }

    public void setCanvas(Canvas canvas) {
        this.canvas = canvas;
    }

    public int getViewShow() {
        return viewShow;
    }

    public void setViewShow(int viewShow) {
        this.viewShow = viewShow;
    }

    public float getAhcjl() {
        try {
            ArrayList<GongZuoMian_Model> gzmms= OperateMyDatabaseImpl.getAllResult(AllGlobal.GONGZUOMIAN_SQL);
            if(gzmms.size()>0){
                GongZuoMian_Model gzmm=gzmms.get(0);
                this.ahcjl=Float.valueOf(gzmm.getAhcjl());
            }
           
        } catch (Exception ex) {
            Logger.getLogger(MyController.class.getName()).log(Level.SEVERE, null, ex);
        }
        return ahcjl;
    }

    public void setAhcjl(float ahcjl) {
        this.ahcjl = ahcjl;
    }

    public DiCengOper getDco() {
        return dco;
    }
    public void attachDco(DiCengOper dco){
        this.dco=dco;
    }

    public float getMEICENGQINGJIAOF() {
        return MEICENGQINGJIAOF;
    }

    public void setMEICENGQINGJIAOF(float MEICENGQINGJIAOF) {
        this.MEICENGQINGJIAOF = MEICENGQINGJIAOF;
    }
    
    
}
